package main

import (
	"fmt"
	"net/http"
	"os"
)

func myHandler(w http.ResponseWriter, r *http.Request) {
	str := r.URL.String()

	f, err := os.Open("c:/Users/stormfat/Pictures" + str)
	defer f.Close()
	if err != nil {
		fmt.Println("file open err:", err)
		return
	}
	buf := make([]byte, 4096)
	for {
		n, err := f.Read(buf)
		if n == 0 {
			fmt.Println(string([]byte("file trans ok")))
			return
		} else if err != nil {
			w.Write([]byte("file trans err"))
			return
		}
		w.Write(buf[:n])

	}

}

func main() {
	var str1 string
	http.HandleFunc("/"+str1, myHandler) //注册回调函数,该函数在客户端访问服务器时被自动调用

	http.ListenAndServe("127.0.0.1:8000", nil) //绑定服务器监听地址
}
